﻿#include "bslLabelAndPushButton.h"
#include "ui_bslLabelAndPushButton.h"




bslLabelAndPushButton::bslLabelAndPushButton(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::bslLabelAndPushButton)
{
    ui->setupUi(this);
    this->setAutoFillBackground(true);
    QPalette  Palette= this->palette();
    Palette.setColor(QPalette::Background,Qt::white);
    this->setPalette(Palette);



    m_pLabel          = new QLabel(this);
    m_pPushButton     = new QPushButton(this);
    m_pPushButton->setFixedHeight(60);
    m_pPushButton->setFixedWidth(300);

    m_pGridLayout     = new QGridLayout(this);
    m_pGridLayout->setSpacing(0);
    m_pGridLayout->setMargin(2);
    m_pGridLayout->setColumnMinimumWidth(0,20);

    m_pGridLayout->addWidget(m_pLabel,0,1);
    m_pGridLayout->addWidget(m_pPushButton,0,2);
    setLayout(m_pGridLayout);




    connect(m_pPushButton,&QPushButton::clicked,this,
            [=]()
    {
        m_bIfExpend = !m_bIfExpend;
        mExpend(m_bIfExpend);
    });
}



bslLabelAndPushButton::~bslLabelAndPushButton()
{
    delete ui;
}



void bslLabelAndPushButton::mAddSubWidget(QWidget* pSubWidget)
{
    pSubWidget->setParent(this);
    pSubWidget->setVisible(m_bIfExpend);

    int nItemNum = m_pGridLayout->count();
    m_pGridLayout->addWidget(pSubWidget,nItemNum,1);
}



void bslLabelAndPushButton::mExpend(bool IfExpand)
{

    m_bIfExpend = IfExpand;
    int nItemNum = m_pGridLayout->count();
    int i;
    for(i = 2; i<nItemNum;++i)
    {
        auto Item= m_pGridLayout->itemAt(i);
        if(Item->widget())
        {
            Item->widget()->setVisible(IfExpand);

        }
    }
}
